/*
 * @Author: 火红色祥云 809880192@qq.com
 * @Date: 2023-09-26 22:12:29
 * @LastEditors: 火红色祥云 809880192@qq.com
 * @LastEditTime: 2023-10-01 18:00:16
 * @FilePath: /imx6ull-app/24_modbus/tcpip/main.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "modbus_tcp.hpp"

int main(int argc, char *argv[])
{
    uint8_t read_buffer[1024];
    uint8_t write_buffer[1024];
    uint16_t read_buffer_16[3];
    uint16_t write_buffer_16[1024];
    modbus::modbus_tcp modbus("192.168.1.107",60000);  //创建一个modbus_tcp对象

    modbus.read_coil_status(0x0000, 5, read_buffer);//00 01 00 00 00 06 01   01 67 89 00 05 
    modbus.read_input_status(0x0000, 5, read_buffer);//00 01 00 00 00 06 01    01 67 89 00 05 
    modbus.read_holding_register(0x0000, 5, read_buffer_16);//00 01 00 00 00 06 01   01 67 89 00 05 
    modbus.read_input_register(0x0000, 5, read_buffer_16);//00 01 00 00 00 06 01    04 67 89 00 05 
    modbus.write_single_coil(0x0000, 0x1234);
    modbus.write_single_register(0x0000, 0x1234);//0x06：写单个保持寄存器: 00 01 00 00 00 06 01    06 67 89 12 34
    modbus.write_multiple_coil(0x0000, 5, write_buffer);//0x0F（15）：写多个线圈: 00 01 00 00 00 08 01     0F 67 89 00 05 01 1F
    modbus.write_multiple_registers(0x0000, 5,  write_buffer_16);    //0x10（16）：写多个保持寄存器: 00 01 00 00 00 11 01   10 67 89 00 05 0A 00 00 00 00 00 00 00 00 00 05 
}

/**
000000-Rx:00 01 00 00 00 06 01 01 00 00 00 05 
000001-Tx:00 01 00 00 00 04 01 01 01 10 
000002-Rx:00 02 00 00 00 06 01 02 00 00 00 05 
000003-Tx:00 02 00 00 00 04 01 02 01 0F 
000004-Rx:00 03 00 00 00 06 01 03 00 00 00 05 
000005-Tx:00 03 00 00 00 0D 01 03 0A 00 4D 00 4A 00 45 00 43 00 40 
000006-Rx:00 04 00 00 00 06 01 04 00 00 00 05 
000007-Tx:00 04 00 00 00 0D 01 04 0A 00 3A 00 38 00 36 00 33 00 31 
000008-Rx:00 05 00 00 00 06 01 05 00 00 FF 00 
000009-Tx:00 05 00 00 00 06 01 05 00 00 FF 00 
000010-Rx:00 06 00 00 00 06 01 06 00 00 12 34 
000011-Tx:00 06 00 00 00 06 01 06 00 00 12 34 
000012-Rx:00 07 00 00 00 08 01 0F 00 00 00 05 01 01 
000013-Tx:00 07 00 00 00 06 01 0F 00 00 00 05 
000014-Rx:00 08 00 00 00 11 01 10 00 00 00 05 0A 00 00 00 00 00 00 00 00 00 00 
000015-Tx:00 08 00 00 00 06 01 10 00 00 00 05 
*/
